package cn.samler.diandi.api.utils;

import cn.samler.diandi.api.model.io.Response;

import java.util.HashMap;

public class ResponseBuilder {
    private int ret = Response.RetCode.RET_SUCCESS;
    private String msg = "success";
    private Object data = null;

    public Response build() {
        return Response.getInstance(ret, msg, data);
    }

    public ResponseBuilder ret(int ret) {
        this.ret = ret;
        return this;
    }

    public ResponseBuilder msg(String msg) {
        this.msg = msg;
        return this;
    }

    public ResponseBuilder data(Object data) {
        this.data = data;
        return this;
    }

    public ResponseBuilder success() {
        this.ret = Response.RetCode.RET_SUCCESS;
        this.msg = "success";

        return this;
    }

    public ResponseBuilder failure() {
        this.ret = Response.RetCode.RET_FAILURE;
        this.msg = "failure";

        return this;
    }

    public ResponseBuilder tokenInvalid() {
        this.ret = Response.RetCode.RET_ACCESS_TOKEN_INVALID;
        this.msg = "access token invalid";

        return this;
    }

    public ResponseBuilder tokenRefreshed(String token) {
        this.ret = Response.RetCode.RET_ACCESS_TOKEN_REFRESHED;
        this.msg = "access token refreshed";
        this.data = new HashMap<String, Object>(){
            {
                this.put("access_token", token);
            }
        };

        return this;
    }

}
